using System;
using System.Collections.Generic;
using System.Text;
using MoEngine;

namespace MoGameLib
{
    public class SiteTypeCollection : ICollection<SiteType>
    {
        #region ICollection<SiteType> Members

        protected Dictionary<Name, SiteType> m_SiteTypes = new Dictionary<Name,SiteType>();

        public void Add(SiteType item)
        {
            if (item.Name == null)
                throw new Exception("[SiteType] null name");

            if (m_SiteTypes.ContainsKey(item.Name))
                throw new Exception("[SiteType] name already taken");

            m_SiteTypes[item.Name] = item;
        }

        public void Clear()
        {
            m_SiteTypes.Clear();
        }

        public bool Contains(SiteType item)
        {
            return m_SiteTypes.ContainsValue(item);
        }

        public void CopyTo(SiteType[] array, int arrayIndex)
        {
            m_SiteTypes.Values.CopyTo(array, arrayIndex);
        }

        public int Count
        {
            get { return m_SiteTypes.Count; }
        }

        public bool IsReadOnly
        {
            get { return false; }
        }

        public bool Remove(SiteType item)
        {
            return m_SiteTypes.Remove(item.Name);
        }

        #endregion

        #region IEnumerable<SiteType> Members

        public IEnumerator<SiteType> GetEnumerator()
        {
            return m_SiteTypes.Values.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        #endregion

        public SiteType this[Name name]
        {
            get { return m_SiteTypes[name]; } 
        }
    }
}
